<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<!-- 功能模块: ${codeName} -->
<mapper namespace="${className}Mapper" >
	
	<!--user customize code start-->
${userCustomCode}
	<!--user customize code end  -->
	
	<!--通用查询条件组装-->
	<sql id="whereCondition">
		<#list columnDatas as item>
		<#if item.dataType == 'Date' >
			<if test="querySectionMap.${item.domainPropertyName}Begin != null">
				AND  ${item.columnName}<![CDATA[>=]]>${"#"}{querySectionMap.${item.domainPropertyName}Begin,jdbcType=${item.jdbcDataType}}  
			</if>
			<if test="querySectionMap.${item.domainPropertyName}End != null">
				AND  ${item.columnName}<![CDATA[<=]]>${"#"}{querySectionMap.${item.domainPropertyName}End,jdbcType=${item.jdbcDataType}}  
			</if>
		<#else>
			<if test="${item.domainPropertyName} != null">
				AND  ${item.columnName}=${"#"}{${item.domainPropertyName},jdbcType=${item.jdbcDataType}}  
			</if>
		</#if>
		</#list>
	</sql>
	<!--通用查询条件组装-->
	
	<!--查询字段列表拼装-->
	<sql id="baseColumnList">
		<#list columnDatas as item>
			<#if item_index==0>
			 ${item.columnName}		 
			<#else>
			,${item.columnName}		 
			</#if>
		</#list> 	
	</sql>
	<!--查询字段列表拼装-->
	
	<!--
	方法名称: insert
	调用路径: ${className}Mapper.insert
	开发信息: 
	处理信息: 保存记录
	-->
 	<insert id="insert" parameterType="${entityPackage}.${className}" >
	 	INSERT  INTO  ${tableNameUpper}
			<trim prefix="(" suffix=")" suffixOverrides=",">
				<#list columnDatas as item>
					<if test="${item.domainPropertyName} != null">
					${item.columnName},
					</if>
				</#list>
			</trim>
			<trim prefix="values (" suffix=")" suffixOverrides=",">
				 <#list columnDatas as item>
					<if test="${item.domainPropertyName} != null">
					 ${"#"}{${item.domainPropertyName},jdbcType=${item.jdbcDataType}},
					</if>
				 </#list>
			</trim>
	</insert>
	
	
	<!--
	方法名称: update
	调用路径: ${className}Mapper.update
	开发信息: 
	处理信息: 修改记录
	-->
 	<update id="update" parameterType="${entityPackage}.${className}" >
		UPDATE   ${tableNameUpper}
	  	<set>
		<#list columnDatas as item>
			<#if item.columnKey !='PRI' >
				<#if item.columnName == 'LAST_UPDATE_NO'>
				<if test="${item.domainPropertyName} != null">
			 		${item.columnName} = ${"#"}{${item.domainPropertyName},jdbcType=${item.jdbcDataType}}+1,
			 	</if>
				<#else>
				<if test="${item.domainPropertyName} != null">
			 		${item.columnName} = ${"#"}{${item.domainPropertyName},jdbcType=${item.jdbcDataType}},
			 	</if>
			 	</#if>
			</#if>
		</#list>
		</set>
		WHERE  
		<#list columnKeyDatas as item>
			<#if item_index==0>
			${item.columnName} = ${"#"}{${item.domainPropertyName},jdbcType=${item.jdbcDataType}}		 
			<#else>
		 	AND ${item.columnName} = ${"#"}{${item.domainPropertyName},jdbcType=${item.jdbcDataType}}		 
			</#if>
		</#list>
		<#list columnDatas as item>
			<#if item.columnName == 'LAST_UPDATE_NO'>
		<if test="${item.domainPropertyName} != null">
	 		AND ${item.columnName} = ${"#"}{${item.domainPropertyName},jdbcType=${item.jdbcDataType}}  
	 	</if>
		 	</#if>
		</#list>
	</update>

	
	<#if columnKeyParam !="">
	<!--
	方法名称: deleteByPriKey
	调用路径: ${className}Mapper.deleteByPriKey
	开发信息: 
	处理信息: 删除记录
	-->
	<delete id="deleteByPriKey" parameterType="${entityPackage}.${className}">
		DELETE 	FROM ${tableNameUpper}
		WHERE 
		<#list columnKeyDatas as item>
			<#if item_index==0>
			${item.columnName} = ${"#"}{${item.domainPropertyName},jdbcType=${item.jdbcDataType}}		 
			<#else>
		 	AND ${item.columnName} = ${"#"}{${item.domainPropertyName},jdbcType=${item.jdbcDataType}}		 
			</#if>
		</#list>
	</delete>
	</#if>
	
	<#if columnKeyParam !="">
	<!--
	方法名称: findByPriKey
	调用路径: ${className}Mapper.findByPriKey
	开发信息: 
	处理信息: 根据主键查询记录
	-->
	<select id="findByPriKey" parameterType="${entityPackage}.${className}"  resultType="${entityPackage}.${className}">
		SELECT   
		   <include refid="baseColumnList"/>
		FROM   ${tableNameUpper}         
		WHERE
		<#list columnKeyDatas as item>
			<#if item_index==0>
			${item.columnName} = ${"#"}{${item.domainPropertyName},jdbcType=${item.jdbcDataType}}		 
			<#else>
		 	AND ${item.columnName} = ${"#"}{${item.domainPropertyName},jdbcType=${item.jdbcDataType}}		 
			</#if>
		</#list>
	</select>
	</#if>
	
	<!--
	方法名称: getPagenationList
	调用路径: ${className}Mapper.getPagenationList
	开发信息: 
	处理信息: 分页查询记录
	-->
	<select id="getPagenationList" parameterType="${entityPackage}.${className}"  resultType="${entityPackage}.${className}">
		<!-- 分页条 -->
		<include refid="jr.commons.paginationPrefix"/>
		SELECT   
	 		<include refid="baseColumnList"/>
		FROM   ${tableNameUpper}          
		WHERE 1=1
		<include refid="whereCondition"/>
	 	<choose>
			<when test="columnSort != null and columnSort!=''">
			ORDER BY ${"$"}{columnSort}
			</when>
			<otherwise>
			<#if columnKeyParam !="">
			ORDER BY ${columnKeySort}
			</#if>
			</otherwise>
		</choose>
		<!-- 分页条 -->
		<include refid="jr.commons.paginationSuffix"/>
	</select>
	
	<!--
	方法名称: getPagenationList-count
	调用路径: ${className}Mapper.getPagenationList-Count
	开发信息: 
	处理信息: 查询记录数
	-->
	<select id="getPagenationList-count" parameterType="${entityPackage}.${className}" resultType="java.util.HashMap">
		SELECT 
		COUNT(1) CNT
		<#list columnDatas as item>
		   <#if item.needSumFlag=='Y'>
		    ,IFNULL(SUM(${tablesAsName}.${item.columnName}),0) AS	${item.columnName}_SUM
		   </#if>
		</#list> 
		FROM  ${tableNameUpper}  AS ${tablesAsName}   
		 WHERE 1=1
		<include refid="whereCondition"/>
	</select>
	
	<!--
	方法名称: getList
	调用路径: ${className}Mapper.getList
	开发信息: 
	处理信息: 查询所有的记录
	-->
	<select id="getList" parameterType="${entityPackage}.${className}"  resultType="${entityPackage}.${className}">
	    SELECT   
	    <#list columnDatas as item>
		   <#if item_index==0>
		      ${tablesAsName}.${item.columnName}	   AS	${item.domainPropertyName}
		   <#else>
			 ,${tablesAsName}.${item.columnName}	   AS	${item.domainPropertyName}
		   </#if>
	    </#list>
	    FROM   ${tableNameUpper}      AS ${tablesAsName}
	    WHERE 1=1
		<include refid="whereCondition"/>
		<choose>
			<when test="columnSort != null and columnSort!=''">
			ORDER BY ${"$"}{columnSort}
			</when>
			<otherwise>
			<#if columnKeyParam !="">
			ORDER BY ${columnKeySort}
			</#if>
			</otherwise>
		</choose>
	</select>
	
</mapper>